package cn.oms.commons.util;

import cn.oms.commons.pojo.entity.Day;
import lombok.extern.slf4j.Slf4j;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 说明：
 *
 * @author：ChenJJ
 * @date: 2023/6/20
 **/
@Slf4j
public class getDay {

    public static Day week(){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        String stat_datetime= LocalDate.now().toString();
        int d=1;
        ArrayList<String> list = new ArrayList<>();
        for (int i=0;i<7;i++){
            Date parse = formatter.parse(stat_datetime, new ParsePosition(0));
            calendar.setTime(parse);
            //i ---->后几天，-i ---->前几天
            //calendar.add(Calendar.DATE,i);
            calendar.add(Calendar.DATE,-i);
            Date time = calendar.getTime();
            String toTime = formatter.format(time);
            list.add(toTime);
            d++;
        }
        Day day = new Day();
        day.setSun(list.get(6));
        day.setSat(list.get(5));
        day.setFri(list.get(4));
        day.setThu(list.get(3));
        day.setWed(list.get(2));
        day.setTue(list.get(1));
        day.setMon(list.get(0));
        return day;
    }
}
